home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / utilities / cli / bb2cli.lha / BBgoesCLI / BB2Exe.asm next >
Encoding:
Assembly Source File  |  1992-09-02  |  6.2 KB  |  260 lines

  1.  
  2. **********************************************************
  3. *          BB2Exe v1.0               22.12.1994          *
  4. **********************************************************
  5. * copyright (c) 1994 by Jens Tröger, all rights reserved *
  6. *               this is Public Domain                    *
  7. **********************************************************
  8. *        written using HiSoft`s DevPac 3.04              *
  9. * thanx to Francois Rouaix who puts the C source into PD *
  10. * greets fly to Oliver Reiff, "PackMAN" Falk Zühlsdorff  *
  11. * "Janosh" Jan Stötzer, Jan van den Baard,...            *
  12. **********************************************************
  13. * (non)sense: this will read the Bootblock from a given  *
  14. * floppy-drive and then write to an executable           *
  15. * works with KS1.2 and better                            *
  16. * USAGE: BB2Exe <unit> <file>                            *
  17. **********************************************************
  18.  
  19.     opt    o+,p+ 
  20.  
  21.     move.l    a0,a5 
  22.  
  23. ; ----- alloc memory for bootblock and several structures 
  24.  
  25. alloc_mem    move.l    4.w,a6 
  26.     move.l    #1024+88,d0    ; Bootblock + Port/IO... 
  27.     move.l    #$10001,d1 
  28.     jsr    -198(a6)        ; _LVOAllocMem 
  29.     move.l    d0,a4        ; a4: PTR to mem
  30.      beq    exit 
  31.  
  32. ; -----  open dos.library
  33.  
  34. open_dos    lea    dosname(pc),a1 
  35.     moveq    #33,d0 
  36.     jsr    -552(a6)        ; _LVOOpenLibrary 
  37.     move.l    d0,d6        ; d6: DOSBase
  38.     beq    free_mem 
  39.  
  40. ; -----  get unit 
  41.  
  42. read_unit    cmp.b    #"d",(a5)+ 
  43.     bne    usage 
  44.     cmp.b    #"f",(a5)+ 
  45.     bne    usage 
  46.     moveq    #0,d0 
  47.     move.b    (a5)+,d0 
  48.     sub.b    #48,d0 
  49.     cmp.b    #4,d0 
  50.     bge    usage
  51.     cmp.b    #0,d0
  52.     blt    usage
  53.     move.l    d0,d2         ; d2: Unit 
  54.     cmp.b    #":",(a5)+ 
  55.     bne    usage
  56.     adda.l    #1,a5
  57.     move.l    a5,a0 
  58. .loop    cmp.b    #10,(a0)+
  59.     bne.s    .loop
  60.     move.b    #0,-(a0)
  61.  
  62. ; -----  add MessagePort to system
  63.  
  64. add_port    sub.l    a1,a1 
  65.     jsr    -294(a6)        ; _LVOFindTask 
  66.     move.l    d0,1024+16(a4) 
  67.     lea    1024(a4),a1
  68.     jsr    -354(a6)        ; _LVOAddPort 
  69.  
  70. ; -----  open trackdisk.device 
  71.  
  72. open_track    lea    trackname(pc),a0 
  73.     lea    1024+32(a4),a1    ; a1: DiskIO-Struc 
  74.     move.l    d2,d0 
  75.     moveq    #0,d1 
  76.     jsr    -444(a6)        ; _LVOOpenDevice 
  77.     tst.l    d0 
  78.     bne    err_nodev        ; FATAL !!!!!
  79.  
  80. ; -----  read bootblock 
  81.  
  82. read_bb    lea    1024+46(a4),a0    ; a0: RepPort 
  83.     lea           1024(a4),a1    ; a1: ReplyPort-Struc 
  84.     move.l    a1,(a0) 
  85.     lea    1024+32(a4),a1    ; a1: DiskIO-Struc 
  86.     move.w    #2,28(a1) 
  87.     move.l    #1024,36(a1) 
  88.     move.l    a4,40(a1) 
  89.     move.l    #0,44(a1) 
  90.     jsr    -456(a6)        ; _LVODoIO 
  91.     move.l    d0,d2
  92.     move    #9,28(a1) 
  93.     move.l    #0,36(a1) 
  94.     jsr    -456(a6)        ; _LVODoIO 
  95.     tst.l    d2
  96.     bne    err_nodoio
  97.  
  98. ; -----  close trackdisk.device 
  99.  
  100. close_dev    lea     1024+32(a4),a1    ; a1: DiskIO-Struc 
  101.     jsr    -450(a6)        ; _LVOCloseDevice 
  102.  
  103. ; -----  remove port 
  104.  
  105. rem_port    lea    1024(a4),a1    ; a1: ReplyPort 
  106.     jsr    -360(a6)        ; _LVORemPort 
  107.  
  108. ; -----  open exe-file 
  109.  
  110. open_exe    move.l    d6,a6 
  111.     move.l    #1006,d2        ; MODE: NEW_FILE 
  112.     move.l    a5,d1
  113.     jsr    -30(a6)        ; _LVOOpen
  114.     move.l    d0,d7        ; d7: File-Handle 
  115.      beq    no_open 
  116.  
  117. ; -----  write
  118.  
  119. write    lea     hunk_tab1(pc),a2    ; hunk_header
  120.     moveq    #40,d3
  121.     bsr    write_exe
  122.     cmp.l    #40,d0
  123.     bne    no_write
  124.  
  125.     lea    12(a4),a2        ; code
  126.     move.l    #1012,d3
  127.     bsr    write_exe
  128.     cmp.l    #1012,d0
  129.     bne.s    no_write
  130.  
  131.     lea    hunk_tab2(pc),a2    ; hunk_end
  132.     moveq    #4,d3
  133.     bsr.s    write_exe
  134.     cmp.l    #4,d3
  135.     bne.s    no_write
  136.  
  137. ; -----  close up clearly
  138.  
  139. close_file    move.l    d7,d1
  140.     jsr    -36(a6)        ; _LVOClose  
  141.  
  142. ; -----  close dos.library
  143.  
  144. close_dos    move.l    4.w,a6 
  145.     move.l    d6,a1 
  146.     jsr    -414(a6)        ; _LVOCloseLibrary 
  147.  
  148. ; -----  free allocated memory 
  149.  
  150. free_mem    move.l    a4,a1 
  151.     move.l    #1024+88,d0 
  152.     jsr    -210(a6)        ; _LVOFreeMem 
  153.  
  154. ; -----  returncode: 0 
  155.  
  156. exit    moveq    #0,d0 
  157.     rts 
  158.  
  159. ; -----  several messages
  160.  
  161. usage    lea    usage_text(pc),a2 
  162.     move.l    #usage_text_end-usage_text,d3 
  163.     bsr.s    write_msg 
  164.     bra    close_dos 
  165.  
  166. err_nodev    lea    err1_text(pc),a2 
  167.     moveq    #38,d3 
  168.     bsr.s    write_msg
  169.     move.l    4.w,a6
  170.     lea    1024(a4),a1    ; a1: ReplyPort 
  171.     jsr    -360(a6)        ; _LVORemPort 
  172.     bra.s    close_dos
  173.  
  174. err_nodoio    lea    err2_text(pc),a2 
  175.     moveq    #44,d3 
  176.     bsr.s    write_msg
  177.     move.l    4.w,a6
  178.     lea     1024+32(a4),a1    ; a1: DiskIO-Struc 
  179.     jsr    -450(a6)        ; _LVOCloseDevice 
  180.      lea    1024(a4),a1    ; a1: ReplyPort 
  181.     jsr    -360(a6)        ; _LVORemPort 
  182.     bra.s    close_dos
  183.  
  184. no_open    lea    err3_text(pc),a2 
  185.     moveq      #25,d3 
  186.     bsr.s    write_msg 
  187.     bra    close_dos 
  188.  
  189. no_write    lea    err4_text(pc),a2 
  190.     moveq    #37,d0 
  191.     bsr.s    write_msg 
  192.     bra.s    close_file 
  193.  
  194. ; -----  this writes data to exe-file
  195.  
  196. write_exe    move.l    d7,d1
  197.     move.l    a2,d2
  198.     jmp    -48(a6)        ; _LVOWrite
  199.  
  200. ; -----  write text to stdout
  201.  
  202. write_msg    move.l    d6,a6 
  203.     jsr    -60(a6)        ; _LVOOutput 
  204.     move.l    d0,d1 
  205.     move.l    a2,d2 
  206.     jmp    -48(a6)        ; _LVOWrite 
  207.  
  208. ; -----  names, texts
  209.  
  210. dosname    dc.b    "dos.library",0 
  211.     even 
  212. trackname    dc.b    "trackdisk.device",0 
  213.     even 
  214. err1_text    dc.b    "FATAL ERROR opening trackdisk.device.",10 
  215.     even 
  216. err2_text    dc.b    "Error reading Bootblock. No disk inserted ?",10 
  217.     even 
  218. err3_text    dc.b    "Cannot open Output-File.",10 
  219.     even 
  220. err4_text    dc.b    "Error writing to File. Aborting.",10 
  221.     even
  222. usage_text    dc.b    10,$9b,"1mBB2Exe v1.0",$9b,"0m 1994 by Jens Tröger",10 
  223.     dc.b    "USAGE: BB2Exe <unit> <file>",10 
  224.     dc.b    "Where <unit> is one of your mounted floppies (df0:) "
  225.     dc.b    "and <file> is the Path/Name of the file.",10,10 
  226. usage_text_end 
  227.  
  228. ; -----  NOTE: MY Amiga does not accept only one hunk, so I added a dummy
  229. ; -----  hunkt to the executable file with size of 1 long (4 bytes...) but
  230. ; -----  the curious thing is that this hunkt is NOT placed into the exe-
  231. ; -----  file...
  232. ; -----  NOTE: The system loads a6 with ExecBase BEFORE the bootcode runs
  233. ; -----  and so the bootcode does not need to load ExecBase. Thats why I 
  234. ; -----  add the OpCode $2c780004 as the first instruction, cause many 
  235. ; -----  bootcodes dont load ExecBase (I always code this way...)
  236. ; -----  NOTE: I dont care for initialised io-struc of trackdisk.device
  237. ; -----  which is placed by the system in a1  (THIS COULD CAUSE A TRASH)
  238. ; -----  NOTE: much bootcode writes directly to memory, which was NOT
  239. ; -----  allocated (they write direct to chip-ram so they may overwrite 
  240. ; -----  YOUR code -> TRASH)
  241.  
  242. ; -----  SO BE CAREFUL EXECUTING A BOOTBLOCK !!!!!!!!!!!!!!!!!
  243.  
  244. hunk_tab1    dc.l    $000003f3        ; huk_header
  245.     dc.l    $00000000        ; no names
  246.     dc.l    $00000002        ; 2 hunks to load (*)
  247.     dc.l    $00000000        ; first hunk - hunk 0
  248.     dc.l    $00000001        ; last hunk - hunk 1
  249.     dc.l    $000000fe        ; size of first hunk (code)
  250.     dc.l    $00000001        ; siza of second hunk (dummy)
  251.     
  252.     dc.l    $000003e9        ; start of code
  253.     dc.l    $000000fe        ; length of code
  254.     
  255.     dc.l    $2c780004        ; OpCode:   move.l 4.w,a6
  256.  
  257. hunk_tab2    dc.l    $000003f2        ; hunk_end
  258.  
  259.     end 
  260.